package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> list(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProjectVo> page = nursingProjectMapper.list(name,status);
        NursingProjectVo nursingProjectVo = new NursingProjectVo();
//        PageResponse response = new PageResponse();
//        response.setPage(pageNum);
//        response.setPageSize(pageSize);
//        response.setTotal(page.getTotal());
//        response.setRecords(page.getResult());
//        PageResponse response = PageResponse.of(java.util.Optional.ofNullable(page));
        PageResponse response = PageResponse.of(page,nursingProjectVo.getClass());
        return response;
    }

    @Override
    public void addProject(NursingProjectDto dto) {
        NursingProject pojo = new NursingProject();
        BeanUtils.copyProperties(dto,pojo);
        nursingProjectMapper.addProject(pojo);

    }

    @Override
    public NursingProjectVo quaryById(Integer id) {
        NursingProjectVo nursingProjectVo = nursingProjectMapper.quaryById(id);
        return nursingProjectVo;
    }

    @Override
    public void update(NursingProjectDto dto) {
        NursingProject pojo = new NursingProject();
        BeanUtils.copyProperties(dto,pojo);
        nursingProjectMapper.update(pojo);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        nursingProjectMapper.updateStatus(id,status);
    }

    @Override
    public void delete(Integer id) {
        nursingProjectMapper.delete(id);
    }

    @Override
    public List<NursingProjectVo> getAllproject() {
        List<NursingProjectVo> list = nursingProjectMapper.getAllProject();
        return list;
    }
}
